<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>8_3_2-设置动画过程中的监听回调</title>
</head>

<body>


    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <div id="Application">
        <button @click="click">显示/隐藏</button>
        <transition name="ani" @before-enter="beforeEnter" @enter="enter" @after-enter="afterEnter"
            @enter-cancelled="enterCancelled" @before-leave="beforeLeave" @leave="leave" @after-leave="afterLeave"
            @leave-cancelled="leaveCancelled">
            <div v-if="show" class="demo"></div>
        </transition>
    </div>
    <script>
        const App = Vue.createApp({
            data() {
                return {
                    show: false
                }
            },
            methods: {
                click() {
                    this.show = !this.show
                },
                //组件插入过度开始前
                beforeEnter(el) {
                    console.log("beforeEnter")
                },

                //组件插入过渡开始
                enter(el, done) {
                    console.log("enter")
                },

                //组件插入过渡后
                afterEnter(el) {
                    console.log("afterEnter")
                },

                //组件插入过渡取消
                enterCancelled(el) {
                    console.log("enterCancelled")
                },

                //组件移除过渡开始前
                beforeLeave(el) {
                    console.log("beforeLeave")
                },

                //组件移除过渡开始
                leave(el, done) {
                    console.log("leave")
                },

                //组件移除过渡后
                affterLeave(el) {
                    console.log("afterLeave")
                },

                //组件移除过渡取消
                leaveCancelled(el) {
                    console.log("leveCancelled")
                }
            }
        })
        App.mount("#Application")
    </script>

    <style>
        @keyframes keyframes-in {
            from {
                width: 0px;
                height: 0px;
                background-color: red;
            }

            to {
                width: 100px;
                height: 100px;
                background-color: blue;
            }
        }

        @keyframes keyframes-out {
            from {
                width: 100px;
                height: 100px;
                background-color: blue;
            }

            to {
                width: 0px;
                height: 0px;
                background-color: red;
            }
        }

        /*默认样式*/
        .demo {
            width: 100px;
            height: 100px;
            background-color: rgb(207, 106, 11);
        }

        .ani-enter-from {
            width: 0px;
            height: 0px;
            background-color: red;
        }

        .ani-enter-active {
            animation: keyframes-in 3s;
        }

        .ani-enter-to {
            width: 100px;
            height: 100px;
            background-color: blue;
        }

        .ani-leave-from {
            width: 100px;
            height: 100px;
            background-color: blue;
        }

        .ani-leave-active {
            animation: keyframes-out 3s;
        }

        .ani-leave-to {
            width: 0px;
            height: 0px;
            background-color: red;
        }
    </style>
</body>

</html>